<?php
class Zend_Validate_PassVerify extends Zend_Validate_Abstract
{

    protected $minimum = 4;
    protected $maximum = 16;

    const INVALID		='regexInvalid';
    const NOT_MATCH		='regexNotMatch';
    const ERROROUS		='regexErrorous';
	const STRINGSHORT	='stringShort';
	const STRINGERROR	='passError';
	const PASSSIMPLE	='passSimple';
	const NOTLATIN		='notLatin';
	

 protected $_messageTemplates = array(
        self::INVALID		=> "String contains invalid characters",
        self::NOT_MATCH 	=> "Does not match against pattern '%pattern%'",
        self::ERROROUS		=> "There was an internal error while using the pattern '%pattern%'",
		self::PASSSIMPLE	=>"Your password is too simple",
		self::STRINGERROR	=>"'%value%' contains characters which are non alphabetic and no digits",
		self::NOTLATIN		=>"Characters must contain only letters and Arabic numerals",
	
    );

protected $_messageVariables = array(
		'min' 	=> 'minimum',
		'max' 	=> 'maximum'
		);

	public function isValid($value)
    {
		$length = mb_strlen($value);		
		$this->_setValue($value);
	if(!is_string($value))
	{
	$this->_error(self::INVALID);
	return false;
	}
		if(preg_match("/^[а-яё]+[\d]+$/iu",$value) || preg_match("/[а-яё]/iu",$value))
		{
		$this->_error(self::NOTLATIN);
		return false;
		}

		if(!preg_match("/^[^ !@#$%^&*()+\|?\\\.\/\[\]\'\"`~={}:;]+[\w]+[\w]+$/i",$value) && $length > $this->minimum || preg_match("/^[!@#$%^&*()+\|?\\\.\/\[\]\'\"`~={}:;]+$/",$value) )
		{
		$this->_error(self::STRINGERROR);
		return false;
		}
		
		if(preg_match("/^[\d]+$/",$value) || preg_match("/^[a-z]+$/i",$value))
		{
		$this->_error(self::PASSSIMPLE);
		return false;
		}
		return true;
	
	}
}
